import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class IteratorDemo {

	public static void main(String[] args) {

	  Collection<String> someCollection = new ArrayList<String>();
		someCollection.add("Milo");
		someCollection.add("Nakov");
		someCollection.add("Martin");

		Iterator<String> i = someCollection.iterator();
		while (i.hasNext()) {
			String element = i.next();
			System.out.println(element);
		}
		
		System.out.println("----------------");
		
		List<Integer> someList = new LinkedList<Integer>();
		
		someList.add(5);
		someList.add(25);
		someList.add(15);

		ListIterator<Integer> listIt = someList.listIterator();
		while (listIt.hasNext()) {
		  System.out.println(listIt.next());
		}
		
		System.out.println("----------------");
		
		String[] names = { "Milo", "Nakov", "Martin" };
		iterate(Arrays.asList(names).iterator());

	}

	public static <E> void iterate(Iterator<E> i) {
		while (i.hasNext()) {
			System.out.println(i.next());
		}
	}

}
